package com.group.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.group.dao.CommonMapper;
import com.group.pojo.Common;
import com.group.service.CommonService;

@Service
public class CommonServiceImpl implements CommonService{
	
	@Autowired
	private CommonMapper commonMapper;

	public String getTbCurrentDateNextId(Common common) {
		String tbCurrentDateMaxId = commonMapper.getTbCurrentDateMaxId(common);
		
		long tbCurrentDateNextId = 0;
		if (tbCurrentDateMaxId != null && !"0".equals(tbCurrentDateMaxId)) {
			tbCurrentDateNextId = Long.parseLong(tbCurrentDateMaxId)+1;
		} else {
			tbCurrentDateNextId = Long.parseLong(new SimpleDateFormat("yyyyMMdd").format(new Date()) + "000001");
		}
		return String.valueOf(tbCurrentDateNextId);
	}

	@Override
	public String getColumnNameByIdAndTbName(Common common) {
		String resultName = commonMapper.getColumnNameByIdAndTbName(common);
		return resultName;
	}

}
